const router = require('express').Router()
const { Comment } = require('@/models')
const { data } = require('@/utils/send')

router.get('/', async (req, res) => {
    try {
        const { movie_id } = req.query
        // 查询评论
        const comment = await Comment.findAll({
            where: {
                movie_id
            }
        })
        const datas = data({ message: '查询成功', data: comment })
        res.send(datas)
        res.locals.data = datas
    } catch (error) {
        res.cc(error)
    }
})
router.post('/', async (req, res) => {
    try {
        const { movie_id, user_id, content } = req.body
        const comment = await Comment.create({
            movie_id,
            user_id,
            content
        })
        const datas = data({ message: '评论成功', data: comment })
        res.send(datas)
        res.locals.data = datas
    } catch (error) {
        res.cc(error)
    }
})
module.exports = router